package csci6450.chickenFriedFS.nuggetClient.threads.functions;

import csci6450.chickenFriedFS.nuggetClient.threads.MetaServerCommunicator;
import csci6450.chickenFriedFS.nuggetCore.NuggetConstants;
import java.io.IOException;
import java.net.UnknownHostException;

/**
 *
 * @author jacobschoen
 */
public class StopMetaServer extends MetaServerCommunicator {

    public boolean execute() throws UnknownHostException, IOException, ClassNotFoundException {
        this.initializeConnection();
        this.getOutputStream().writeObject(NuggetConstants.STOP);
        this.getOutputStream().flush();
        this.closeConnection();
        boolean stopped = false;
        for (int i = 0; !stopped && i < 3000; i = i + 1) {
            if (this.getSocket().isClosed()) {
                try {
                    TimestampMetaServer timestamp = new TimestampMetaServer();
                    timestamp.execute();
                } catch (Exception ce) {
                    stopped = true;
                }
            }
        }
        return stopped;
    }
}
